<template>
  <div class="toolbar colorMain">
    <div class="mt-10 mb-10">
      <el-form :inline="true" size="small">
        <el-form-item label="日期筛选"><date-picker v-model="queryFrom.time_range"/></el-form-item>
        <el-form-item v-if="!(['witch', 'loki'].includes($store.state.user.business))" label="渠道" size="small"><channel v-model="queryFrom.chn_filter_list"/></el-form-item>
        <el-form-item v-if="!(['witch', 'loki'].includes($store.state.user.business))" label="留存类型" >
          <el-select v-model="queryFrom.stay_type" placeholder="请选择" class="input">
            <el-option v-for="(item, index) in stayArray" :key="index" :label="item" :value="index" />
          </el-select>
        </el-form-item>
        <el-form-item v-if="!(['witch', 'loki'].includes($store.state.user.business))" label="用户类型"><user-type v-model="queryFrom.user_type"/></el-form-item>
        <el-form-item v-if="!(['witch', 'loki'].includes($store.state.user.business))" label="展示类型" >
          <el-select v-model="queryFrom.display_type" placeholder="请选择" class="input">
            <el-option v-for="(item, index) in displayType" :key="index" :label="item" :value="index" />
          </el-select>
        </el-form-item>
        <el-button size="small" type="primary" @click="sendQuery">提交</el-button>
      </el-form>
    </div>
    <div><el-button :loading="excelLoad" icon="el-icon-printer" style="float: right;margin: 0 0 10px 0" size="mini" type="success" @click="downExcel" >导出数据</el-button></div>
    <analyse-table v-if="showTable" :table-data="tableData" :key_mapper="key_mapper" :sortable = "['user_id', 'chn']" :min-width = "160" size="small" @sort-change="sortChange"/>
    <el-pagination :current-page.sync="page" :page-size="size" :total.sync="total" class="mt-10" layout="total, sizes, prev, pager, next, jumper" @current-change="currentChange" @size-change="handleSizeChange"/>
  </div>
</template>
<script>
import { pickTime } from '@/model/DateRange'
import { getNewUserStayAnalysis } from '@/api/table'
import mixins from '@/model/mixins'

export default {
  name: 'UserStay',
  mixins: [mixins],
  data() {
    return {
      displayType: {
        percentage: '百分比展示',
        normal: '数据展示'
     },
      stayArray: {
        user_stay: '新增注册留存',
        device_stay: '新增设备留存', register_stay: '绑定留存', bet_stay: '投注留存',
        // free_bet_stay: '免费活跃留存',
        recharge_stay: '付费留存', one_recharge_stay: '一次付费留存', multi_recharge_stay: '多次付费留存',
        win_stay: '玩法盈利留存', lose_stay: '玩法亏损留存'
      },
      queryFrom: {
        time_range: pickTime,
        user_type: ''
      },
      API: getNewUserStayAnalysis,
      showTable: true
    }
  },
  watch: {
    tableData() {
      this.showTable = false
      this.$nextTick(() => (
        this.showTable = true
      ))
    }
  }
}
</script>
